﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bootstrap5.Design
{
    internal class GridRowDecoratorProvider : GridDecoratorProvider
    {
        public GridRowDecoratorProvider() : base(GridType.RowCol)
        {
        }
    }

    internal class GridColumnDecoratorProvider : GridDecoratorProvider
    {
        public GridColumnDecoratorProvider() : base(GridType.Column)
        {
        }
    }

    internal class GridColumnOffsetDecoratorProvider : GridDecoratorProvider
    {
        public GridColumnOffsetDecoratorProvider() : base(GridType.Offset)
        {
        }
    }

    internal abstract class GridDecoratorProvider : BreakPointClassDecoratorProvider<GridSize, BreakingPointModel, IGridDecorator>, IGridDecorator
    {
        private readonly GridType _gridType;

        protected GridDecoratorProvider(GridType gridType)
        {
            this._gridType = gridType;
        }

        public IGridDecorator Is1 => GetKey(GridSize.Is1);

        public IGridDecorator Is2 => GetKey(GridSize.Is2);

        public IGridDecorator Is3 => GetKey(GridSize.Is3);

        public IGridDecorator Is4 => GetKey(GridSize.Is4);

        public IGridDecorator Is5 => GetKey(GridSize.Is5);

        public IGridDecorator Is6 => GetKey(GridSize.Is6);

        public IGridDecorator Is7 => GetKey(GridSize.Is7);

        public IGridDecorator Is8 => GetKey(GridSize.Is8);

        public IGridDecorator Is9 => GetKey(GridSize.Is9);

        public IGridDecorator Is10 => GetKey(GridSize.Is10);

        public IGridDecorator Is11 => GetKey(GridSize.Is11);

        public IGridDecorator Is12 => GetKey(GridSize.Is12);

        public IGridDecorator IsAuto => GetKey(GridSize.Auto);

        protected override IGridDecorator GetBreakPoint(BreakPoint value)
        {
            SetBreakPoint(value);
            return this;
        }
        protected override IGridDecorator GetKey(GridSize value)
        {
            SetKey(value);
            return this;
        }

        protected override void BuildClass()
{
            Rules.AddRange(RuleDic.Select(m => GetCssClass(m.Key, m.Value)));
        }

        string GetCssClass(GridSize column, IEnumerable<BreakingPointModel> values)
        {
            return string.Join(" ", values.Select(m => GetCssClass(column, m.BreakPoint)));
        }

        string GetCssClass(GridSize column, BreakPoint? breakingPoint)
        {
            var builder = new StringBuilder(_gridType.GetEnumCssClass());
            builder.Append(CssClassHelper.STRIPER);
            if (breakingPoint.HasValue)
            {
                builder.Append(breakingPoint.Value.GetEnumCssClass()).Append(CssClassHelper.STRIPER);
            }
            builder.Append(column.GetEnumCssClass());
            return builder.ToString();
        }
    }
}
